const fs = require('fs');
const path = require('path');

const excludeFiles = ['app.js', 'index.js'];

function register(app) {
  const files = fs.readdirSync(path.join(__dirname, './'));

  files.forEach(fileName => {
    if (!excludeFiles.includes(fileName)) {
      const filePath = path.join(__dirname, fileName);
      const router = require(filePath);

      app.use(router.routes()).use(router.allowedMethods());
    }
  });
}

module.exports = {
  register,
};
